package trunk.frontend;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.*;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class TextBoxOptions extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JButton jbSubmit;
	private JButton jbCancel;
	private JTextField jtfLabelText;
	private JTextField jtfText;
	private WFBFrame parent;

	public TextBoxOptions(WFBFrame myParent) {
		super("Text Field Creator");
		setPreferredSize(new Dimension(100, 300));
		jtfLabelText = new JTextField(12);
		jtfText = new JTextField(12);
		JLabel jlTitle = new JLabel("Optional Text Box Label: ");
		JLabel jlWhatContents = new JLabel("Fill in Contents Here: ");
		jbSubmit = new JButton("Submit");
		jbSubmit.addActionListener(this);
		jbCancel= new JButton("Cancel");
		jbCancel.addActionListener(this);
		GridBagLayout gbl = new GridBagLayout();
		GridBagConstraints gbc = new GridBagConstraints();
		
		setSize(new Dimension(400, 150));
		
		gbc.anchor = GridBagConstraints.NORTH;
		gbc.gridx = GridBagConstraints.RELATIVE;
		gbc.gridy = 0;
		
		getContentPane().setLayout(gbl);
		getContentPane().add(jlTitle, gbc);
		getContentPane().add(jtfLabelText, gbc);
		gbc.gridy = 1;
		getContentPane().add(jlWhatContents, gbc);
		getContentPane().add(jtfText, gbc);
		
		gbc.anchor = GridBagConstraints.CENTER;
		gbc.gridy = 2;
		
		getContentPane().add(jbSubmit, gbc);
		getContentPane().add(jbCancel, gbc);
		
		parent = myParent;
		setVisible(true);
	}
	
	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == jbSubmit) {
			parent.addToForm(new String("1#:@" + jtfLabelText.getText() + "#:@"
					+ jtfText.getText()));
			dispose();
			//setVisible(false);
		}
		else if (ae.getSource() == jbCancel) {
			dispose();
			//setVisible(false);
		}
	}
	
}
